<?php
/** Class Person
* Manager person
**/

class Person extends admin_controller
{
	function __construct()
	{
		parent::__construct();
		$this->load->model('person/person_model');
	}

	public function index(){
		$this->breadcrumb = array(
			'Dashboard' => URL_ADMIN,
			'Person'	=> URL_ADMIN.'person',
		);

		$persons = $this->db->get('person')->result_array();
		$personBad = $this->db->get_where('person', array('bad >' => 0))->result_array();
		$this->template->title()
				->set(array('persons' => $persons, 'personBad' => $personBad))
			  	->build('admin/person/index');
	}

	/**Function manager comment 
	* return list comment
	**/
	public function comment() {

		$this->breadcrumb = array(
			'Dashboard' => URL_ADMIN,
			'Person'	=> URL_ADMIN.'person',
			'Comment' => ''
		);

		$pid = (int)$this->uri->segment(4);
		if($pid && $pid !== "") {
			$allComments = $this->db->select('id, comment, time_added')->get_where('comment', array('personId' => $pid))->result_array();
			//$dislikeComments = $this->db->select('id, comment, time_added')->get_where('comment', array('personId' => $pid, 'dislike >=' => 20))->result_array();
		} else {
			$allComments = $this->db->select('id, comment, time_added')->get('comment')->result_array();
			//$dislikeComments = $this->db->select('id, comment, time_added')->get_where('comment', array('dislike >=' => 20))->result_array();	
		}

		$this->template->title()
				->set(array('allComments' => $allComments))
			  	->build('admin/person/comment');
	}

	public function photo(){
		$pid = (int)$this->uri->segment(4);

		$this->breadcrumb = array(
			'Dashboard' => URL_ADMIN,
			'Person'	=> URL_ADMIN.'person',
			'Photo of '. $this->person_model->get_name_person($pid) => ''
		);

		$photos = $this->db->select('id, photo')->get_where('photo_person', array('person_id' => $pid))->result_array();

		$namePerson = $this->person_model->get_name_person($pid);
		$this->template->title()
				->set(array('photos' => $photos, 'nameperson' => $namePerson))
			  	->build('admin/person/photo');	
	}

	public function video(){
		$pid = (int)$this->uri->segment(4);

		$this->breadcrumb = array(
			'Dashboard' => URL_ADMIN,
			'Person'	=> URL_ADMIN.'person',
			'Video of '. $this->person_model->get_name_person($pid) => ''
		);

		$photos = $this->db->select('id, url_video, date_added')->get_where('person_video', array('personId' => $pid))->result_array();

		$namePerson = $this->person_model->get_name_person($pid);
		$this->template->title()
				->set(array('videos' => $photos, 'nameperson' => $namePerson))
			  	->build('admin/person/video');	
	}

	/* Function delete a person from database
	* return TRUE or FALSE
	*/
	public function delete(){
		$pId = (int)$this->uri->segment(4);
		if($this->person_model->delete($pId)) {
			$arr = array('status' => TRUE);
		} else {
			$arr = array('status' => FALSE);
		}
		echo json_encode($arr);
	}

	public function delete_cm(){
		$id = (int)$this->uri->segment(4);	
		$this->db->delete('like_comment', array('commentId' => $id));
		if($this->db->delete('comment', array('id' => $id))) {
			$arr = array('status' => TRUE);
		} else {
			$arr = array('status' => FALSE);	
		}

		echo json_encode($arr);
	}

	public function delete_video(){
		$id = (int)$this->uri->segment(4);	
		if($this->db->delete('person_video', array('id' => $id))) {
			$arr = array('status' => TRUE);
		} else {
			$arr = array('status' => FALSE);	
		}

		echo json_encode($arr);
	}

	public function delete_pic(){
		$id = (int)$this->uri->segment(4);	
		if($this->person_model->delete_pic($id)) {
			$arr = array('status' => TRUE);
		} else {
			$arr = array('status' => FALSE);	
		}

		echo json_encode($arr);
	}

}
/**End file member.php **/
/* File local: application/controller/admin/member.php */